import flash.geom.Transform;

function renderPortlet(slot)
{
	trace("renderPortlet: "+slot);
	
	var mainBg=mlf.gatekeeper.native.Caller.scanElement(slot, "conBg");
	var containerFilter:flash.filters.DropShadowFilter=new flash.filters.DropShadowFilter(10,90,0x000000,80,35,35,0.5,2);
	var bgFilterArr:Array=new Array();
	bgFilterArr.push(containerFilter);
	mainBg.filters=bgFilterArr;

	mainBg._alpha=80;

	var location=mlf.gatekeeper.native.Caller.scanElement(slot, "location");
	var locationFilter=new flash.filters.DropShadowFilter();
	/*for (var a in locationFilter)
	{
		trace(a+": "+locationFilter[a]);
	}*/
	locationFilter.color=0xffffff;
	var locFilterArr:Array=new Array();
	locFilterArr.push(locationFilter);
	location.filters=locFilterArr;
}

function highlightBlock(target:MovieClip)
{
	// trace("highlightBlock: "+target);
	
	var borderColor:Number=0x99defd;
	var fillColorStart:Number=0xf0f8fd;
	var fillColorEnd:Number=0xd5effc;

	// target._alpha=100;
	
	target.lineStyle(0, borderColor);
	target.moveTo(0, 0);
	var colors=[fillColorStart, fillColorEnd];
	var alphas=[100, 100];
	var ratios=[0, 0xff];
	var matrix={matrixType:"box", x:100, y:0, w:300, h:16, r:(90/180)*Math.PI};
	target.beginGradientFill("linear", colors, alphas, ratios, matrix);
	target.lineTo(target._width, 0);
	target.lineTo(target._width, target._height);
	target.lineTo(0, target._height);
	target.lineTo(0, 0);
	target.endFill();
}

function highlightBG(target:MovieClip, cover:MovieClip, alpha:Number)
{
	// trace("highlightBG "+target+" "+cover+" "+alpha);
	cover._x=target._x;
	cover._y=target._y;
	cover._alpha=alpha;
}

function renderTextStyle(slot, ins, fmt, dropColor)
{
	var target=mlf.gatekeeper.native.Caller.scanElement(slot, ins);
	target.setTextFormat(fmt);
	var targetFilter=new flash.filters.DropShadowFilter();
	targetFilter.color=dropColor;
	var tarFilterArr:Array=new Array();
	tarFilterArr.push(targetFilter);
	target.filters=tarFilterArr;
}

function messageHint(slot:String, content:String, type:String, callbackObj:Object)
{
	var pCacheCallbackObj=callbackObj;
	var messTf=mlf.gatekeeper.native.Caller.scanElement(slot, "messageHint");
	var cloud=mlf.gatekeeper.native.Caller.scanElement(slot, "cloud");
	trace("cloud: "+cloud);
	cloud.onPress=null;
	if (callbackObj!=null)
	{
		cloud.onPress=function()
		{
			Packages.system.MLF.invoke(pCacheCallbackObj);
		}
	}
	var hintCloud=cloud.media_cloud.hintCloud;
	messTf.htmlText=content;
	if (type=="warning")
	{
		hintCloud.gotoAndStop(2);
	}
	else if (type=="hint")
	{
		hintCloud.gotoAndStop(3);
	}
	else hintCloud.gotoAndStop(1);
}

function focusManager()
{
	var focusListener:Object=new Object();
	focusListener.onSetFocus=function(oldFocus_txt, newFocus_txt) 
	{
		if (mlf.mcmanager.PathResolver.drawPath(oldFocus_txt).indexOf("tf_txt")>-1)
		{
			oldFocus_txt.borderColor=0x50565b;
			oldFocus_txt.background=false;
		}
		if (mlf.mcmanager.PathResolver.drawPath(newFocus_txt).indexOf("tf_txt")>-1)
		{
			newFocus_txt.borderColor=0x99defd;
			newFocus_txt.background=true;
			newFocus_txt.backgroundColor=0xffffff;
		}
	};
	Selection.addListener(focusListener);
}

function displayHint(param, data, slot)
{
	// var target=mlf.mcmanager.PathResolver.extractPath(param);
	var hintLayer=mlf.gatekeeper.native.Caller.scanElement(slot, "hintLayer");
	var falseTarget=hintLayer.createEmptyMovieClip("falseTarget", hintLayer.getNextHighestDepth());
	falseTarget.lineStyle(0, 0x000000);
	falseTarget.moveTo(0, 0);
	falseTarget.lineTo(2, 0);
	falseTarget.lineTo(2, 2);
	falseTarget.lineTo(0, 2);
	falseTarget.lineTo(0, 0);
	falseTarget.endFill();
	falseTarget._x=_root._xmouse;
	falseTarget._y=_root._ymouse;
	falseTarget._alpha=0;
	var hintInstance=hintLayer.createEmptyMovieClip("hintInstance", hintLayer.getNextHighestDepth());
	var eleArr=param.split("-");
	var content=Packages.system.MLF.scanDictionary(hintLayer, "Hint_"+eleArr[eleArr.length-1]);
	Packages.system.Util.createHint(falseTarget, content, hintInstance);
}

function disposeHint(param, data, slot)
{
	Packages.system.Util.removeHint();
	var hintLayer=mlf.gatekeeper.native.Caller.scanElement(slot, "hintLayer");
	hintLayer.hintInstance.removeMovieClip();
	hintLayer.falseTarget.removeMovieClip();
}

focusManager();